Enter the directory of the maca folder on your drive and the name of the tissue you want to analyze.
tissue_of_interest = "Bladder"
Load the requisite packages and some additional helper functions.
library(here)
here() starts at /Users/olgabot/code/tabula-muris
library(useful)
Loading required package: ggplot2
library(Seurat)
Loading required package: cowplot
Attaching package: 'cowplot'
The following object is masked from 'package:ggplot2':
ggsave
Loading required package: Matrix
Warning: namespace 'Biobase' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'lme4' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'MatrixModels' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'Biobase' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'lme4' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'MatrixModels' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
library(dplyr)
Warning: package 'dplyr' was built under R version 3.4.2
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(Matrix)
save_dir = here('00_data_ingest', 'tissue_robj')
# read the metadata to get the plates we want
plate_metadata_filename = here('00_data_ingest', '00_facs_raw_data', 'metadata_FACS.csv')
plate_metadata <- read.csv(plate_metadata_filename, sep=",", header = TRUE)
colnames(plate_metadata)[1] <- "plate.barcode"
plate_metadata
Load the plate data. “Bladder” is one of the tissues studied
tissue_plates = filter(plate_metadata, tissue == tissue_of_interest)[,c('plate.barcode','tissue','subtissue','mouse.sex')]
tissue_plates
Load the read count data.
#Load the gene names and set the metadata columns by opening the first file
filename = here('00_data_ingest', '00_facs_raw_data', 'FACS', paste0(tissue_of_interest, '-counts.csv'))
raw.data = read.csv(filename, sep=",", row.names=1)
# raw.data = data.frame(row.names = rownames(raw.data))
corner(raw.data)
Make a vector of plate barcodes for each cell
plate.barcodes = lapply(colnames(raw.data), function(x) strsplit(strsplit(x, "_")[[1]][1], '.', fixed=TRUE)[[1]][2])
head(plate.barcodes)
[[1]]
[1] "D041914"
[[2]]
[1] "D041914"
[[3]]
[1] "D041914"
[[4]]
[1] "D041914"
[[5]]
[1] "D041914"
[[6]]
[1] "D041914"
D041914
D041914
D041914
D041914
D041914
D041914
Use only the metadata rows corresponding to Bladder plates. Make a plate barcode dataframe to “expand” the per-plate metadata to be per-cell.
barcode.df = t.data.frame(as.data.frame(plate.barcodes))
rownames(barcode.df) = colnames(raw.data)
colnames(barcode.df) = c('plate.barcode')
head(barcode.df)
plate.barcode
A12.D041914.3_8_M.1.1 "D041914"
B16.D041914.3_8_M.1.1 "D041914"
C18.D041914.3_8_M.1.1 "D041914"
D22.D041914.3_8_M.1.1 "D041914"
F4.D041914.3_8_M.1.1 "D041914"
C19.D041914.3_8_M.1.1 "D041914"
D041914
D041914
D041914
D041914
D041914
D041914
rnames = row.names(barcode.df)
meta.data <- merge(barcode.df, plate_metadata, by='plate.barcode', sort = F)
row.names(meta.data) <- rnames
head(meta.data)
Process the raw data and load it into the Seurat object.
# Find ERCC's, compute the percent ERCC, and drop them from the raw data.
erccs <- grep(pattern = "^ERCC-", x = rownames(x = raw.data), value = TRUE)
percent.ercc <- Matrix::colSums(raw.data[erccs, ])/Matrix::colSums(raw.data)
ercc.index <- grep(pattern = "^ERCC-", x = rownames(x = raw.data), value = FALSE)
raw.data <- raw.data[-ercc.index,]
# Create the Seurat object with all the data
tiss <- CreateSeuratObject(raw.data = raw.data, project = tissue_of_interest,
min.cells = 5, min.genes = 5)
tiss <- AddMetaData(object = tiss, meta.data)
tiss <- AddMetaData(object = tiss, percent.ercc, col.name = "percent.ercc")
# Change default name for sums of counts from nUMI to nReads
colnames(tiss@meta.data)[colnames(tiss@meta.data) == 'nUMI'] <- 'nReads'
# Create metadata columns for annotations and subannotations
tiss@meta.data[,'annotation'] <- NA
tiss@meta.data[,'subannotation'] <- NA
Calculate percent ribosomal genes.
ribo.genes <- grep(pattern = "^Rp[sl][[:digit:]]", x = rownames(x = tiss@data), value = TRUE)
percent.ribo <- Matrix::colSums(tiss@raw.data[ribo.genes, ])/Matrix::colSums(tiss@raw.data)
tiss <- AddMetaData(object = tiss, metadata = percent.ribo, col.name = "percent.ribo")
A sanity check: genes per cell vs reads per cell.
GenePlot(object = tiss, gene1 = "nReads", gene2 = "nGene", use.raw=T)
Filter out cells with few reads and few genes.
tiss <- FilterCells(object = tiss, subset.names = c("nGene", "nReads"),
low.thresholds = c(500, 50000), high.thresholds = c(25000, 2000000))
Normalize the data, then regress out correlation with total reads
tiss <- NormalizeData(object = tiss)
tiss <- ScaleData(object = tiss, vars.to.regress = c("nReads", "percent.ribo","Rn45s"))
[1] "Regressing out nReads" "Regressing out percent.ribo"
[3] "Regressing out Rn45s"
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 6%
|
|==== | 7%
|
|===== | 7%
|
|===== | 8%
|
|====== | 9%
|
|====== | 10%
|
|======= | 10%
|
|======= | 11%
|
|======== | 12%
|
|======== | 13%
|
|========= | 14%
|
|========== | 15%
|
|========== | 16%
|
|=========== | 17%
|
|============ | 18%
|
|============ | 19%
|
|============= | 20%
|
|============== | 21%
|
|============== | 22%
|
|=============== | 23%
|
|================ | 24%
|
|================ | 25%
|
|================= | 26%
|
|================= | 27%
|
|================== | 27%
|
|================== | 28%
|
|=================== | 29%
|
|=================== | 30%
|
|==================== | 30%
|
|==================== | 31%
|
|===================== | 32%
|
|===================== | 33%
|
|====================== | 33%
|
|====================== | 34%
|
|====================== | 35%
|
|======================= | 35%
|
|======================= | 36%
|
|======================== | 36%
|
|======================== | 37%
|
|======================== | 38%
|
|========================= | 38%
|
|========================= | 39%
|
|========================== | 40%
|
|========================== | 41%
|
|=========================== | 41%
|
|=========================== | 42%
|
|============================ | 43%
|
|============================ | 44%
|
|============================= | 44%
|
|============================= | 45%
|
|============================== | 46%
|
|============================== | 47%
|
|=============================== | 48%
|
|================================ | 49%
|
|================================ | 50%
|
|================================= | 51%
|
|================================== | 52%
|
|=================================== | 53%
|
|=================================== | 54%
|
|==================================== | 55%
|
|==================================== | 56%
|
|===================================== | 56%
|
|===================================== | 57%
|
|====================================== | 58%
|
|====================================== | 59%
|
|======================================= | 59%
|
|======================================= | 60%
|
|======================================== | 61%
|
|======================================== | 62%
|
|========================================= | 62%
|
|========================================= | 63%
|
|========================================= | 64%
|
|========================================== | 64%
|
|========================================== | 65%
|
|=========================================== | 65%
|
|=========================================== | 66%
|
|=========================================== | 67%
|
|============================================ | 67%
|
|============================================ | 68%
|
|============================================= | 69%
|
|============================================= | 70%
|
|============================================== | 70%
|
|============================================== | 71%
|
|=============================================== | 72%
|
|=============================================== | 73%
|
|================================================ | 73%
|
|================================================ | 74%
|
|================================================= | 75%
|
|================================================= | 76%
|
|================================================== | 77%
|
|=================================================== | 78%
|
|=================================================== | 79%
|
|==================================================== | 80%
|
|===================================================== | 81%
|
|===================================================== | 82%
|
|====================================================== | 83%
|
|======================================================= | 84%
|
|======================================================= | 85%
|
|======================================================== | 86%
|
|========================================================= | 87%
|
|========================================================= | 88%
|
|========================================================== | 89%
|
|========================================================== | 90%
|
|=========================================================== | 90%
|
|=========================================================== | 91%
|
|============================================================ | 92%
|
|============================================================ | 93%
|
|============================================================= | 93%
|
|============================================================= | 94%
|
|============================================================== | 95%
|
|============================================================== | 96%
|
|=============================================================== | 96%
|
|=============================================================== | 97%
|
|=============================================================== | 98%
|
|================================================================ | 98%
|
|================================================================ | 99%
|
|=================================================================| 99%
|
|=================================================================| 100%
[1] "Scaling data matrix"
|
| | 0%
|
|=================================================================| 100%
tiss <- FindVariableGenes(object = tiss, do.plot = TRUE, x.high.cutoff = Inf, y.cutoff = 0.5)
Run Principal Component Analysis.
tiss <- RunPCA(object = tiss, do.print = FALSE)
tiss <- ProjectPCA(object = tiss, do.print = FALSE)
Later on (in FindClusters and TSNE) you will pick a number of principal components to use. This has the effect of keeping the major directions of variation in the data and, ideally, supressing noise. There is no correct answer to the number to use, but a decent rule of thumb is to go until the plot plateaus.
PCElbowPlot(object = tiss)
Choose the number of principal components to use.
# Set number of principal components.
n.pcs = 10
The clustering is performed based on a nearest neighbors graph. Cells that have similar expression will be joined together. The Louvain algorithm looks for groups of cells with high modularity–more connections within the group than between groups. The resolution parameter determines the scale…higher resolution will give more clusters, lower resolution will give fewer.
For the top-level clustering, aim to under-cluster instead of over-cluster. It will be easy to subset groups and further analyze them below.
# Set resolution
res.used <- 1
tiss <- FindClusters(object = tiss, reduction.type = "pca", dims.use = 1:n.pcs,
resolution = res.used, print.output = 0, save.SNN = TRUE)
To visualize
# If cells are too spread out, you can raise the perplexity. If you have few cells, try a lower perplexity (but never less than 10).
tiss <- RunTSNE(object = tiss, dims.use = 1:n.pcs, seed.use = 10, perplexity=30)
# note that you can set do.label=T to help label individual clusters
TSNEPlot(object = tiss, do.label = T)
Check expression of genes of interset.
Dotplots let you see the intensity of exppression and the fraction of cells expressing for each of your genes of interest.
VlnPlot(tiss, genes_to_check)
BuildClusterTree(tiss)
[1] "Finished averaging RNA for cluster 0"
[1] "Finished averaging RNA for cluster 1"
[1] "Finished averaging RNA for cluster 2"
[1] "Finished averaging RNA for cluster 3"
[1] "Finished averaging RNA for cluster 4"
[1] "Finished averaging RNA for cluster 5"
[1] "Finished averaging RNA for cluster 6"
[1] "Finished averaging RNA for cluster 7"
An object of class seurat in project Bladder
16192 genes across 1287 samples.
How big are the clusters?
table(tiss@ident)
0 1 2 3 4 5 6 7
245 191 170 165 165 156 99 96
Which markers identify a specific cluster?
clust.markers <- FindMarkers(object = tiss, ident.1 = 0, only.pos = TRUE, min.pct = 0.25, thresh.use = 0.25)
DotPlot(tiss, genes.plot = rownames(clust.markers)[1:20], plot.legend = T)
print(x = head(x= clust.markers, n = 10))
p_val avg_diff pct.1 pct.2
Gsta4 5.449510e-173 1.2019084 0.976 0.538
Ly6d 9.641989e-148 1.0295347 0.976 0.431
Spint2 4.991041e-125 1.0136621 0.984 0.451
Gsto1 7.278784e-123 1.1488027 0.984 0.616
Mgst3 9.400482e-122 0.9860769 0.976 0.505
Wfdc2 1.468817e-121 0.9021909 0.976 0.391
Krt7 3.690925e-118 1.0821662 0.971 0.384
Krt8 5.563169e-117 1.1631260 0.976 0.461
Igfbp2 2.263129e-116 1.1054429 0.976 0.403
Ldhb 7.139784e-114 0.9933108 0.971 0.603
You can also compute all markers for all clusters at once. This may take some time.
tiss.markers <- FindAllMarkers(object = tiss, only.pos = TRUE, min.pct = 0.25, thresh.use = 0.25)
Display the top markers you computed above.
#tiss.markers %>% group_by(cluster) %>% top_n(5, avg_diff)
tiss.markers %>% group_by(cluster) %>% top_n(10, avg_diff)
At a coarse level, we can use canonical markers to match the unbiased clustering to known cell types:
0: alpha 1: beta 2: beta 3: exocrine 4: duct 5: delta 6: gamma 7: endothelial 8: immune 9: stellate
# stash current cluster IDs
tiss <- StashIdent(object = tiss, save.name = "cluster.ids")
# enumerate current cluster IDs and the labels for them
cluster.ids <- c(0, 1, 2, 3, 4, 5, 6, 7)
annotation <- c("bladder cell", "bladder cell", "mesenchymal cell", "mesenchymal cell", "mesenchymal cell", "mesenchymal cell", "basal cell of urothelium", "bladder cell")
cell_ontology_id = c("CL:1001319", "CL:1001319", "CL:0008019", "CL:0008019", "CL:0008019", "CL:0008019", "CL:1000486", "CL:1001319")
tiss@meta.data[,'annotation'] <- plyr::mapvalues(x = tiss@meta.data$cluster.ids, from = cluster.ids, to = annotation)
tiss@meta.data[,'cell_ontology_id'] <- plyr::mapvalues(x = tiss@meta.data$cluster.ids, from = cluster.ids, to = cell_ontology_id)
TSNEPlot(object = tiss, do.label = TRUE, pt.size = 0.5, group.by='annotation')
TSNEPlot(object = tiss, do.return = TRUE, group.by = "mouse.sex")
Color by metadata, like plate barcode, to check for batch effects.
TSNEPlot(object = tiss, do.return = TRUE, group.by = "plate.barcode")
Print a table showing the count of cells in each identity category from each plate.
table(as.character(tiss@ident), as.character(tiss@meta.data$plate.barcode))
B000610 B002764 B002771 D041914 D042253 MAA000487
0 87 2 49 65 17 25
1 2 0 1 1 84 103
2 58 1 10 97 2 2
3 41 0 19 100 3 2
4 1 0 3 1 114 46
5 2 0 3 2 98 51
6 0 0 1 0 24 74
7 6 8 11 50 1 20
# Get markers for a particular cluster
for (i in 0:7) {clustermarkers = filter(tiss.markers, cluster == i)$gene
DotPlot(tiss, genes.plot = clustermarkers[1:20], plot.legend = T)}
# Get subtissue, eg, the endocrine clusters
subtiss <- SubsetData(object = tiss, ident.use = c(2),
do.center = F, do.scale = F)
subtiss <- SubsetData(object = tiss, ident.use = c(2), do.center = F, do.scale = F, cells.use = )
subtiss <- NormalizeData(object = subtiss)
subtiss <- ScaleData(object = subtiss, vars.to.regress = c("nReads", "percent.ribo","Rn45s"))
[1] "Regressing out nReads" "Regressing out percent.ribo"
[3] "Regressing out Rn45s"
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 6%
|
|==== | 7%
|
|===== | 7%
|
|===== | 8%
|
|====== | 9%
|
|====== | 10%
|
|======= | 10%
|
|======= | 11%
|
|======== | 12%
|
|======== | 13%
|
|========= | 14%
|
|========== | 15%
|
|========== | 16%
|
|=========== | 17%
|
|============ | 18%
|
|============ | 19%
|
|============= | 20%
|
|============== | 21%
|
|============== | 22%
|
|=============== | 23%
|
|================ | 24%
|
|================ | 25%
|
|================= | 26%
|
|================= | 27%
|
|================== | 27%
|
|================== | 28%
|
|=================== | 29%
|
|=================== | 30%
|
|==================== | 30%
|
|==================== | 31%
|
|===================== | 32%
|
|===================== | 33%
|
|====================== | 33%
|
|====================== | 34%
|
|====================== | 35%
|
|======================= | 35%
|
|======================= | 36%
|
|======================== | 36%
|
|======================== | 37%
|
|======================== | 38%
|
|========================= | 38%
|
|========================= | 39%
|
|========================== | 40%
|
|========================== | 41%
|
|=========================== | 41%
|
|=========================== | 42%
|
|============================ | 43%
|
|============================ | 44%
|
|============================= | 44%
|
|============================= | 45%
|
|============================== | 46%
|
|============================== | 47%
|
|=============================== | 48%
|
|================================ | 49%
|
|================================ | 50%
|
|================================= | 51%
|
|================================== | 52%
|
|=================================== | 53%
|
|=================================== | 54%
|
|==================================== | 55%
|
|==================================== | 56%
|
|===================================== | 56%
|
|===================================== | 57%
|
|====================================== | 58%
|
|====================================== | 59%
|
|======================================= | 59%
|
|======================================= | 60%
|
|======================================== | 61%
|
|======================================== | 62%
|
|========================================= | 62%
|
|========================================= | 63%
|
|========================================= | 64%
|
|========================================== | 64%
|
|========================================== | 65%
|
|=========================================== | 65%
|
|=========================================== | 66%
|
|=========================================== | 67%
|
|============================================ | 67%
|
|============================================ | 68%
|
|============================================= | 69%
|
|============================================= | 70%
|
|============================================== | 70%
|
|============================================== | 71%
|
|=============================================== | 72%
|
|=============================================== | 73%
|
|================================================ | 73%
|
|================================================ | 74%
|
|================================================= | 75%
|
|================================================= | 76%
|
|================================================== | 77%
|
|=================================================== | 78%
|
|=================================================== | 79%
|
|==================================================== | 80%
|
|===================================================== | 81%
|
|===================================================== | 82%
|
|====================================================== | 83%
|
|======================================================= | 84%
|
|======================================================= | 85%
|
|======================================================== | 86%
|
|========================================================= | 87%
|
|========================================================= | 88%
|
|========================================================== | 89%
|
|========================================================== | 90%
|
|=========================================================== | 90%
|
|=========================================================== | 91%
|
|============================================================ | 92%
|
|============================================================ | 93%
|
|============================================================= | 93%
|
|============================================================= | 94%
|
|============================================================== | 95%
|
|============================================================== | 96%
|
|=============================================================== | 96%
|
|=============================================================== | 97%
|
|=============================================================== | 98%
|
|================================================================ | 98%
|
|================================================================ | 99%
|
|=================================================================| 99%
|
|=================================================================| 100%
[1] "Scaling data matrix"
|
| | 0%
|
|=================================================================| 100%
subtiss <- FindVariableGenes(object = subtiss, do.plot = TRUE, x.high.cutoff = Inf, y.cutoff = 0.8)
subtiss <- RunPCA(object = subtiss, pcs.compute = 20, weight.by.var = F)
[1] "PC1"
[1] "Gsn" "Fbln1" "Pi16" "Entpd2"
[5] "Lbp" "Fxyd5" "Crip2" "Sparcl1"
[9] "Plxdc2" "Col14a1" "Arap1" "Asz1"
[13] "Cd34" "Efna5" "Osr1" "Fxyd6"
[17] "Spon2" "Actg1" "Gm973" "Ifi27l2a"
[21] "Hsd11b1" "Serpina3n" "Inmt" "Fmo1"
[25] "C4b" "1810041L15Rik" "Hspa1a" "Cyp2e1"
[29] "Ednrb" "Akap12"
[1] ""
[1] "Myl9" "Ptgs2" "Plau" "Myh11"
[5] "Gatm" "Acta2" "Pde4b" "Trib1"
[9] "Vcam1" "Nampt" "Pamr1" "Prss35"
[13] "Tagln" "Procr" "Mt1" "Ldha"
[17] "Ereg" "Tnfsf9" "Cish" "Tnfaip3"
[21] "Gpnmb" "Niacr1" "Ccnd2" "Cebpd"
[25] "Rab20" "Rbp4" "Sept4" "1810011O10Rik"
[29] "Nfkbia" "Iigp1"
[1] ""
[1] ""
[1] "PC2"
[1] "Tuba1c" "Ifrd1" "Sparcl1" "Gfpt2" "Ugdh"
[6] "Scara5" "Mat2a" "Metrnl" "Nop58" "Cish"
[11] "Chodl" "Gpr133" "Pi16" "Cebpd" "Nr4a2"
[16] "Nfkbia" "Cd55" "Myc" "Hk2" "Errfi1"
[21] "Tnfrsf12a" "Gadd45b" "Lbp" "Uap1" "Entpd2"
[26] "Il6" "Icam1" "Col14a1" "Bcl3" "Tubb6"
[1] ""
[1] "Rbp4" "Nprl2" "U2af1l4" "Ier2" "Avpr1a" "Tsc22d1"
[7] "Zfyve21" "Tmem204" "Zfp688" "Rnf181" "Cdk9" "Fbxo31"
[13] "Bub3" "Rchy1" "Tubg1" "Cdk5rap1" "Crnkl1" "Qrich1"
[19] "Wdr8" "Spin1" "Glipr2" "Ddx28" "Sept4" "Emilin1"
[25] "Mum1" "Ndp" "Ypel3" "Trim11" "Smyd2" "Rnf114"
[1] ""
[1] ""
[1] "PC3"
[1] "Irf2bp1" "Ide" "4921517L17Rik" "Ddx28"
[5] "Fam53c" "Nudt13" "Skiv2l2" "Fads1"
[9] "Usp21" "Musk" "H2-Aa" "Cnot6"
[13] "Neil1" "Pknox1" "E130308A19Rik" "Ddx17"
[17] "Zfp949" "Rpap3" "Dus2l" "Zfp523"
[21] "Gss" "Gabpb1" "Wdr53" "Gtf2h2"
[25] "Irf9" "Haus4" "Cenpl" "Qtrt1"
[29] "Mxi1" "Mum1"
[1] ""
[1] "Tlk2" "Ptk7" "Cdk5rap1" "Qrich1" "Rilpl1" "Yars2"
[7] "Crnkl1" "Rfxank" "Prep" "Fbxo11" "Gprasp1" "Nkd2"
[13] "Fmo5" "Prpf3" "Fbxo31" "Tmem41a" "Nprl2" "Dom3z"
[19] "Abcg1" "Pld2" "Zfp688" "Pgm5" "Parp3" "Eml3"
[25] "Med4" "Ecm2" "Pkdcc" "Dcxr" "Cstb" "Dgcr6"
[1] ""
[1] ""
[1] "PC4"
[1] "Gna11" "Blvrb" "1810063B07Rik" "A430005L14Rik"
[5] "Atf3" "Pdrg1" "Ier2" "Tmem222"
[9] "9130023H24Rik" "Tor2a" "Rchy1" "Bambi"
[13] "Arl4d" "Paqr5" "Bub3" "Aamp"
[17] "Ahrr" "Tsc22d1" "9430020K01Rik" "Ranbp3"
[21] "Anapc10" "Gmpr2" "Mrpl2" "Ypel3"
[25] "Bmp3" "Sumf2" "Txndc16" "Atpaf2"
[29] "Rtkn" "Mlycd"
[1] ""
[1] "Arhgap21" "Nacc2" "Cdk5rap1" "Rfxank"
[5] "Crnkl1" "Ptk7" "Arfgap2" "Mcmbp"
[9] "Rilpl1" "Rbmx" "Prep" "Ppil4"
[13] "Pcdhgc3" "Tlk2" "Map2k3" "Cnot6"
[17] "Nit2" "Neil1" "Pcsk5" "Fmo5"
[21] "Gprasp1" "H2-Aa" "Eml3" "Fads1"
[25] "Prpf3" "4921517L17Rik" "Lman2l" "Hyal2"
[29] "Nkd2" "Qrich1"
[1] ""
[1] ""
[1] "PC5"
[1] "Calcrl" "Dnaja1" "Ppp1r15a" "Spin1"
[5] "Plat" "Ece1" "Gsn" "Rbp4"
[9] "Lmna" "Sdc4" "Ptn" "Smad3"
[13] "Tspan8" "Cd14" "Cd1d1" "Gadd45b"
[17] "Tcp11l2" "Naaa" "Cxcl12" "Hspa1a"
[21] "2010011I20Rik" "Uap1" "Nfkbia" "Fmo2"
[25] "Fbln5" "Mpv17" "Arl8b" "Rabl3"
[29] "Hbegf" "2010002N04Rik"
[1] ""
[1] "Itih5" "Myl9" "Npy1r" "Mfap5"
[5] "Acta2" "Igfbp4" "Nhsl2" "Actg2"
[9] "Prss35" "Nsg1" "Glul" "Col8a1"
[13] "Mtch2" "Sqrdl" "Serpina3n" "Mgp"
[17] "Mcm7" "Lifr" "Tspan4" "Zfp259"
[21] "Top2a" "Slc9a3r2" "Arhgdib" "Rpap3"
[25] "Fnta" "Pomt2" "8430410A17Rik" "Mki67ip"
[29] "Acy1" "Ddx39"
[1] ""
[1] ""
subtiss <- ProjectPCA(object = subtiss, do.print = FALSE)
# If this fails for your subset, it may be that cells.use is more cells than you have left! Try reducing it.
PCHeatmap(object = subtiss, pc.use = 1:3, cells.use = 250, do.balanced = TRUE, label.columns = FALSE, num.genes = 12)
PCElbowPlot(object = subtiss)
# Set number of principal components.
sub.n.pcs = 5
# Set resolution
sub.res.used <- 1
subtiss <- FindClusters(object = subtiss, reduction.type = "pca", dims.use = 1:sub.n.pcs,
resolution = sub.res.used, ,print.output = 0, save.SNN = TRUE)
# If cells are too spread out, you can raise the perplexity. If you have few cells, try a lower perplexity (but never less than 10).
subtiss <- RunTSNE(object = subtiss, dims.use = 1:sub.n.pcs, seed.use = 10, perplexity=20)
# note that you can set do.label=T to help label individual clusters
TSNEPlot(object = subtiss, do.label = T)
TSNEPlot(object = subtiss, do.return = TRUE, group.by = "mouse.sex")
genes_to_check = c('Hhip','Dcn', 'Gli1','Gli2', 'Smo','Col1a1','Col8a1')
#genes_to_check = c('Alb', 'Cyp2f2', 'Cyp2e1', 'Hamp')
FeaturePlot(subtiss, genes_to_check, pt.size = 1, nCol = 3)
VlnPlot(subtiss, genes_to_check)
clust.markers <- FindMarkers(object = subtiss, ident.1 = 0, only.pos = TRUE, min.pct = 0.25, thresh.use = 0.25)
clust.markers
clust.markersuro <- FindMarkers(object = subtiss, ident.1 = 0, only.pos = TRUE, min.pct = 0.25, thresh.use = 0.25)
clust.markersuro
GenePlot(subtiss, 'Upk3a', 'Krt14', use.raw = T)
Warning in cor(x = data.plot$x, y = data.plot$y): the standard deviation is
zero
BuildClusterTree(subtiss)
[1] "Finished averaging RNA for cluster 0"
[1] "Finished averaging RNA for cluster 1"
[1] "Finished averaging RNA for cluster 2"
[1] "Finished averaging RNA for cluster 3"
An object of class seurat in project Bladder
16192 genes across 170 samples.
VlnPlot(subtiss, genes_to_check)
Later on (in FindClusters and TSNE) you will pick a number of principal components to use. This has the effect of keeping the major directions of variation in the data and, ideally, supressing noise. There is no correct answer to the number to use, but a decent rule of thumb is to go until the plot plateaus.
Check expression of genes of interset.
genes_to_check = c('Btg2','Sgk1','Jun','Srsf2')
FeaturePlot(subtiss, genes_to_check, pt.size = 1)
Dotplots let you see the intensity of exppression and the fraction of cells expressing for each of your genes of interest.
# To change the y-axis to show raw counts, add use.raw = T.
DotPlot(subtiss, genes_to_check, plot.legend = T)
How big are the clusters?
table(subtiss@ident)
0 1 2 3
57 48 43 22
Color by metadata, like plate barcode, to check for batch effects.
TSNEPlot(object = subtiss, do.return = TRUE, group.by = "plate.barcode")
Print a table showing the count of cells in each identity category from each plate.
table(as.character(subtiss@ident), as.character(subtiss@meta.data$plate.barcode))
B000610 B002764 B002771 D041914 D042253 MAA000487
0 15 0 5 35 1 1
1 3 1 0 42 1 1
2 38 0 5 0 0 0
3 2 0 0 20 0 0
When you save the annotated tissue, please give it a name.
filename = here('00_data_ingest', '04_tissue_robj_generated',
paste0(tissue_of_interest, "_seurat_tiss.Robj"))
print(filename)
[1] "/Users/olgabot/code/tabula-muris/00_data_ingest/04_tissue_robj_generated/Bladder_seurat_tiss.Robj"
save(tiss, file=filename)
# To reload a saved object
# filename = here('00_data_ingest', '04_tissue_robj_generated',
# paste0(tissue_of_interest, "_seurat_tiss.Robj"))
# load(file=filename)
So that Biohub can easily combine all your annotations, please export them as a simple csv.
head(tiss@meta.data)
filename = here('00_data_ingest', '03_tissue_annotation_csv',
paste0(tissue_of_interest, "_annotation.csv"))
write.csv(tiss@meta.data[,c('plate.barcode','annotation','cell_ontology_id')], file=filename)